
module.exports = class extends baseController{
    constructor(){
        super();
        this.platformLogic=this.loadLogic('iframe/platform');
        this.router.post('/getItems',this.getItems.bind(this));
        this.router.post('/getItem',this.getItem.bind(this));
        this.router.post('/edit',this.edit.bind(this));
        this.router.post('/del',this.del.bind(this));
        return this.router;
    }

    static init(){
        return new this();
    }

    async getItems(req,res){
        let Result={};
        try{
            var FindFilterModel = {};
            var CurPage = req.body.CurPage ? Number(req.body.CurPage) : 1;
            var PageSize = req.body.PageSize ? Number(req.body.PageSize) : 20;
            var Sort = req.body.Sort ? req.body.Sort : "IP_CreateTime|desc";
            FindFilterModel.IP_Name = req.body.IP_Name;
            FindFilterModel.IP_CreateTime = req.body.IP_CreateTime;
            let ret=await this.platformLogic.getItems(FindFilterModel,CurPage,PageSize,Sort,req.user);
            Result=this.Success(1,ret);
        }catch(err){
            Result=this.Error('数据查询失败',err);
        }
        res.json(Result);
    }

    async getItem(req,res){
        let Result={};
        let model={};
        try{
            let id = Number("0" + req.body.id);
            if(id>0){
                model=await this.platformLogic.getItem(id);
                if(!model){
                   return res.json(this.Error('记录不存在')); 
                }
            }
            Result=this.Success(1,model);
        }catch(err){
            Result=this.Error('数据查询失败',err);
        }
        res.json(Result);
    }

    async edit(req,res){
        let Result={};
        try{
           let model=await this.platformLogic.insertOrUpdate(req.body);
            Result=this.Success(1,model);
        }catch(err){
            Result=this.Error('数据查询失败',err);
        }
        res.json(Result);
    }

    async del(req,res){
        let Result={};
        try{
            let keys = req.body.keys;
            let ret = await this.platformLogic.del(keys);
            Result=this.Success(1,ret);
        }catch(err){
            Result=this.Error('数据查询失败',err);
        }
        res.json(Result);
    }
};




